<template>
	<view class="">
		<image class="bj" :src="bj"></image>
		<image class="back" @click="backFn" :style="{'top': statusBar+'px'}" :src="back"></image>
		<view class="content">
			<view class="user">
				<image :src="info.avatar"></image>
				<view class="right">
					<view class="phone">
						{{info.nickname}}
					</view>
					<view class="time alpsoftjurnal" v-if="vipData.vip_expire_time!='-'">
						{{$t('member.text2')}}：{{vipData.vip_expire_time}}
					</view>
				</view>
			</view>
			<view class="member">
				<image mode="widthFix" style="width: 100%;" :src="bj2"></image>
				<view class="cont">
					<view class="money">
						￥{{vipData.month_vip_coin.current_price}}
					</view>
					<view class="vip">
						vip
					</view>
				</view>
			</view>
			<view class="title alpsoftjurnal">
				{{$t('member.text1')}}
			</view>
			<mp-html :content="vipData.vip_introduce" />
		</view>
		<view class="bottom">
			<view class="button alpsoftjurnal" @click="GoActivate">
				{{$t('GoandActivate')}}
			</view>
		</view>
	</view>
</template>

<script>
import util from '../../../utils/util'
	export default {
		data() {
			return {
				bj: this.$config.staticUrl + 'memberbj.png',
				back: this.$config.staticUrl + 'back2.png',
				bj2: this.$config.staticUrl + 'memberbj2.png',
				statusBar: 0,
				info: {},
				vipData: {}
			}
		},
		onLoad() {
			this.info = uni.getStorageSync('userinfo')
			this.$set(this.info, 'avatar', this.configs.imgUrl+this.info.avatar)
			uni.getSystemInfo({
				success: (e) => {
					this.statusBar = e.statusBarHeight //状态栏高度
				}
			})
			this.vipRule()
		},
		methods: {
			backFn() {
				console.log('返回');
				uni.navigateBack()
			},
			vipRule() {
				uni.request({
					url: this.configs.webUrl + '/api/vip/vipRule',
					data: {
						token: uni.getStorageSync('userinfo').token
					},
					success: res => {
						console.log(res);
						this.vipData = res.data.data
						let index = this.vipData.vip_introduce.indexOf('src=')
						console.log(index);
						this.$set(this.vipData, 'vip_introduce', this.insertCharAt(this.vipData.vip_introduce, this.vipData.image_domain, index+5))
					}
				})
			},
			insertCharAt(str, char, index) {
			  return str.slice(0, index) + char + str.slice(index);
			},
			// 去开通
			GoActivate() {
				uni.request({
					url: this.configs.webUrl + '/api/vip/buyVip',
					data: {
						token: uni.getStorageSync('userinfo').token,
						vip_name: 'month_vip_coin'
					},
					success: res => {
						console.log(res);
						if(res.data.code == 1) {
							uni.navigateBack()
						}
						util.toast(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bj {
		width: 100%;
		z-index: -1;
	}

	.back {
		position: absolute;
		left: 20rpx;
		width: 38rpx;
		height: 40rpx;
	}

	.content {
		position: absolute;
		width: 90%;
		left: 5%;
		top: 10%;
		padding-top: 120px;
		overflow: auto;
		height: 80%;

		.user {
			background: #fff;
			border-radius: 20rpx;
			padding: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			image {
				width: 158rpx;
				height: 158rpx;
				border-radius: 50%;
			}

			.right {
				width: calc(100% - 168rpx);

				.phone {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #47464C;
				}

				.time {
					margin-top: 20rpx;
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #A8A0A0;
				}
			}
		}

		.member {
			margin: 20rpx 0;
			position: relative;

			.cont {
				position: absolute;
				width: 80%;
				left: 10%;
				top: 30%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.money {
					font-size: 90rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #FFF688;
				}

				.vip {
					font-size: 34rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #1E1819;
					padding: 10rpx 20rpx;
					border-radius: 50rpx;
					background: #D5BC8C;
				}
			}
		}

		.title {
			margin: 20rpx 0;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #000000;
		}
	}

	.bottom {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		background: #fff;
		padding: 10rpx 40rpx 50rpx;

		.button {
			height: 84rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 60rpx;
			background: linear-gradient(90deg, #F75581 0%, #C860FF 100%);
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #FFFFFF;
		}
	}
</style>